// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   HoldingProcessor.java

package com.boci.clientapp.holding.processor;

import com.boci.clientapp.holding.vo.HoldingDetailVO;
import com.boci.clientapp.holding.vo.HoldingVO;
import com.boci.common.processor.AbstractResponseProcessor;
import com.boci.common.vo.ResponseVO;
import java.util.ArrayList;
import org.w3c.dom.*;

public class HoldingProcessor extends AbstractResponseProcessor
{

    public HoldingProcessor(String pXML, String pReqType)
        throws Exception
    {
        super(pXML, pReqType, "HOLDING.ERROR_");
        allVOList = new ArrayList();
        hkStockList = new ArrayList();
        usStockList = new ArrayList();
        hkOptionList = new ArrayList();
        usOptionList = new ArrayList();
        otherList = new ArrayList();
    }

    public ResponseVO processXML()
        throws Exception
    {
        HoldingVO holdingVO = new HoldingVO(getReqType(), getReturnCode());
        NodeList holdingDetailList = resultDocument.getElementsByTagName("HOLDINGS_DETAIL");
        transformVOList(holdingDetailList);
        holdingVO.setHoldingDetailVOList(allVOList);
        holdingVO.setHKStockList(hkStockList);
        holdingVO.setUSStockList(usStockList);
        holdingVO.setHKOptionList(hkOptionList);
        holdingVO.setUSOptionList(usOptionList);
        holdingVO.setOtherList(otherList);
        return holdingVO;
    }

    public void transformVOList(NodeList pNodeList)
    {
        int nodeLength = pNodeList.getLength();
        for(int i = 0; i < nodeLength; i++)
        {
            HoldingDetailVO holdingDetailVO = new HoldingDetailVO(getReqType(), getReturnCode());
            Element element = (Element)pNodeList.item(i);
            String strExchangeId = getNodeValue(element, "EXCHANGE_ID");
            String strMarketId = getNodeValue(element, "MARKET_ID");
            String strProductLine = getNodeValue(element, "PRODUCT_LINE");
            String strSymbol = getNodeValue(element, "SYMBOL");
            String strUnderLyingSymbol = getNodeValue(element, "UNDERLYING_SYMBOL");
            String strStockName = getNodeValue(element, "STOCK_NAME");
            String strStockNameChi = getNodeValue(element, "STOCK_NAME_CHI");
            String strStockNameChs = getNodeValue(element, "STOCK_NAME_CHS");
            String strCurrency = getNodeValue(element, "CURRENCY");
            String strPrice = getNodeValue(element, "PRICE");
            String strMarketValue = getNodeValue(element, "MARKET_VALUE");
            String strQuantity = getNodeValue(element, "QUANTITY");
            String strVestedQty = getNodeValue(element, "QUANTITY");
            String strUnvestedQty = getNodeValue(element, "UNAVAILABLE_QUANTITY");
            String strStrikePrice = getNodeValue(element, "PRICE");
            holdingDetailVO.setExchangeId(strExchangeId);
            holdingDetailVO.setMarketId(strMarketId);
            holdingDetailVO.setProductLine(strProductLine);
            holdingDetailVO.setSymbol(strSymbol);
            holdingDetailVO.setUnderLyingSymbol(strUnderLyingSymbol);
            holdingDetailVO.setStockName(strStockName);
            holdingDetailVO.setStockNameChi(strStockNameChi);
            holdingDetailVO.setStockNameChs(strStockNameChs);
            holdingDetailVO.setCurrency(strCurrency);
            holdingDetailVO.setPrice(strPrice);
            holdingDetailVO.setMarketValue(strMarketValue);
            holdingDetailVO.setQuantity(strQuantity);
            holdingDetailVO.setVestedQty(strVestedQty);
            holdingDetailVO.setUnvestedQty(strUnvestedQty);
            holdingDetailVO.setStrikePrice(strStrikePrice);
            allVOList.add(holdingDetailVO);
            String strUpperMarketId = strMarketId.toUpperCase();
            if(strUpperMarketId.equals("HK"))
            {
                hkStockList.add(holdingDetailVO);
                continue;
            }
            if(strUpperMarketId.equals("US"))
            {
                usStockList.add(holdingDetailVO);
                continue;
            }
            if(strUpperMarketId.equals("OPTION"))
            {
                hkOptionList.add(holdingDetailVO);
                continue;
            }
            if(strUpperMarketId.equals("USOPTION"))
                usOptionList.add(holdingDetailVO);
            else
                otherList.add(holdingDetailVO);
        }

    }

    ArrayList allVOList;
    ArrayList hkStockList;
    ArrayList usStockList;
    ArrayList hkOptionList;
    ArrayList usOptionList;
    ArrayList otherList;
}
